package com.zbl.zblproject.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zbl.zblproject.core.entity.Supplier;
import com.zbl.zblproject.erp.entity.ErpTableEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/10/9
 */
@Repository
public interface SupplierMapper extends BaseMapper<Supplier> {

    /**
     * 分页功能
     *
     * @param page
     * @return
     */
    IPage<Supplier> selectPage(Page page);


    List<Integer> selectSupplierIdByOrderSn(@Param("orderSn") List<String> orderSn);


    String selectSupplierNameByGoodsId(@Param("id") Integer id);


    @Select("SELECT * FROM zbl_suppliers WHERE suppliers_name = #{name}")
    Supplier selectSupplierByName(@Param("name") String name);


    @Update("UPDATE zbl_suppliers SET balance = balance - #{total}  WHERE suppliers_id = #{id} ")
    boolean deleteSuplierBalance(@Param("id") int supplierId, @Param("total") BigDecimal money);


    @Update("UPDATE zbl_suppliers SET balance = balance + #{total}  WHERE suppliers_id = #{id} ")
    boolean addSuplierBalance(@Param("id") int supplierId, @Param("total") BigDecimal money);

    @Select("SELECT suppliers_id FROM zbl_goods WHERE goods_id = #{id}")
    Integer selectSupplierIdByGoodsId(@Param("id") int goodsId);


    List<Supplier> selectSupplierByStartInCGDD(@Param("start") long start, @Param("end") long end);

    List<ErpTableEntity> selectSupplierEntity(@Param("start") long start, @Param("end") long end);

    List<ErpTableEntity> selectAnotherSuppliers(@Param("list") List<ErpTableEntity> list);

    List<ErpTableEntity> selectAllSuppliers();

    Page<ErpTableEntity> selectAllSupplierByPage(IPage page);

    ErpTableEntity selectErpTableEntityBySupplier(@Param("supplierId") int supplierId, @Param("start") long start, @Param("end") long end);


    Integer selectGoodsNumberByTimeAndSupplierIdInCGDD(@Param("supplierId") int supplierId, @Param("start") long start, @Param("end") long end);

    BigDecimal selectAllPriceByTimeAndSupplierIdInCGDD(@Param("supplierId") int supplierId, @Param("start") long start, @Param("end") long end);
}
